package com.recipe.controller;

import com.alibaba.fastjson.JSON;
import com.recipe.common.entity.Result;
import com.recipe.entity.vo.BasketVo;
import com.recipe.service.BasketService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lzk
 * @date 2024-06-26 09:55:21
 * @description
 */
@RestController
@RequestMapping("basket")
@Slf4j
@RequiredArgsConstructor
public class BasKetController {

    private final BasketService basketService;

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody BasketVo basketVo) {
        if (log.isInfoEnabled()) {
            log.info("BasKetController.add.basketVo:{}", JSON.toJSONString(basketVo));
        }

        return Result.ok(basketService.add(basketVo));
    }

    @DeleteMapping("/delete")
    public Result<Boolean> delete(String name) {
        if (log.isInfoEnabled()) {
            log.info("BasKetController.delete.name:{}", name);
        }

        return Result.ok(basketService.delete(name));
    }

    @DeleteMapping("/deleteAll")
    public Result<Boolean> deleteAll() {
        if (log.isInfoEnabled()) {
            log.info("BasKetController.deleteAll");
        }

        return Result.ok(basketService.deleteAll());
    }

    @GetMapping("/getAll")
    public Result<List<BasketVo>> get(String name) {
        if (log.isInfoEnabled()) {
            log.info("BasKetController.get.name:{}", name);
        }
        List<BasketVo> list= basketService.getAll();
        return Result.ok(list);
    }
}
